-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-116381: Remove bad specializations, add fail stats #116464
gh-116381: Remove bad specializations, add fail stats #116464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stats gathering needs tidying up a bit, but LGTM otherwise
Python/specialize.c
Outdated
|
||
#ifdef Py_STATS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into its own function, like load_attr_fail_kind
, then this becomes SPECIALIZATION_FAIL(CONTAINS_OP, contains_fail_kind(value))
Python/specialize.c
Outdated
|
||
#ifdef Py_STATS | ||
if (PyUnicode_CheckExact(value)) { | ||
SPECIALIZATION_FAIL(TO_BOOL, SPEC_FAIL_CONTAINS_OP_STR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO_BOOL
-> CONTAINS_OP
and a few more times below
Python/bytecodes.c
Outdated
inst(CONTAINS_OP_STR, (unused/1, left, right -- b)) { | ||
DEOPT_IF(!PyUnicode_CheckExact(right)); | ||
int res = PyUnicode_Contains(right, left); | ||
inst(CONTAINS_OP_MAPPINGPROXY, (unused/1, left, right -- b)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that this is worthwhile.
OOI, what are the numbers for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be. I might just remove it.
On python -m test_typing test_re test_dis test_zlib.
, I get:
frozenset:278
tuple:261
dict:256
list:225
set:150
str:143
mappingproxy:62
dict_values:9
EnumDict:5
collections.OrderedDict:5
collections.defaultdict:4
_Environ:3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I'm not specializing for tuple or list because it's dominated by searching up through the collection anyways so it's not worth it. The rest are O(1) so maybe worth to cut the constant factor.
When you're done making the requested changes, leave the comment: |
I'll leave this between the two of you. (TBH I didn't mean for you to merge gh-116385, I should have been clearer -- I was signing off but expected Mark to have something to say and was hoping for a benchmark.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
…-116464) * Remove bad specializations, add fail stats
…-116464) * Remove bad specializations, add fail stats
Partially reverts some of the bad specializations in #116385. Stats for what are "bad" are from https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20240307-3.13.0a4%2B-72dbea2.
CONTAINS_OP
#116381